/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package control_escolar;

import static control_escolar.inicio.constancia_inicio;
import static control_escolar.log.claves_sesion2;
import static control_escolar.log.expedientes;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author danielsaid
 */
public class Reporte_1 extends javax.swing.JFrame {    

    /**
     * Creates new form Reporte_1
     */
    public Reporte_1() throws IOException {
        initComponents();
        setLocationRelativeTo(null);
        Reloj control_escolar=new Reloj(jlblhora);
        control_escolar.start();
        fecha();
        leerlineayllenarAlumnos();
        leerlineayllenarMaterias();
        leerlineayllenarMaestros();
        semestre();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    
         public Image getIconImage() {
        Image retValue = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("umbrella-corp-2-icon.png"));
        return retValue;
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        nom_materia = new javax.swing.JTextField();
        clav_materia = new javax.swing.JTextField();
        nom_maestro = new javax.swing.JTextField();
        clav_maestro = new javax.swing.JTextField();
        nom_alumno = new javax.swing.JTextField();
        numex_alumno = new javax.swing.JTextField();
        semestre = new javax.swing.JTextField();
        sangre_alum = new javax.swing.JTextField();
        alergias = new javax.swing.JTextField();
        jlblhora = new javax.swing.JLabel();
        jlbldia = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Constancia de Viaje");
        setIconImage(getIconImage());
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("Escuela Superior Big Citrus.");

        jLabel2.setText("Nombre de la Materia:");

        jLabel3.setText("Clave de la Materia:");

        jLabel4.setText("Maestro:");

        jLabel5.setText("Clave de Maestro:");

        jLabel6.setText("Alumno:");

        jLabel7.setText("No. de Exp.Alumno:");

        jLabel8.setText("Semestre:");

        jLabel9.setText("Tipo de Sangre:");

        jLabel10.setText("Alergias:");

        jButton1.setText("Regresar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        nom_materia.setEditable(false);
        nom_materia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nom_materiaActionPerformed(evt);
            }
        });

        clav_materia.setEditable(false);

        nom_maestro.setEditable(false);

        clav_maestro.setEditable(false);

        nom_alumno.setEditable(false);

        numex_alumno.setEditable(false);

        semestre.setEditable(false);

        sangre_alum.setEditable(false);

        alergias.setEditable(false);

        jlblhora.setText("jLabel11");

        jlbldia.setText("jLabel12");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9)
                            .addComponent(jLabel10))
                        .addGap(26, 26, 26)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(alergias)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(numex_alumno, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(nom_alumno, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(clav_maestro, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(nom_maestro, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(nom_materia, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(clav_materia, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(semestre, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                                        .addComponent(sangre_alum, javax.swing.GroupLayout.Alignment.LEADING)))
                                .addGap(0, 14, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(131, 131, 131)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(120, 120, 120)
                        .addComponent(jlblhora, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jlbldia, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(53, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(162, 162, 162))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(nom_materia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(clav_materia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(nom_maestro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(clav_maestro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(nom_alumno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(numex_alumno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(semestre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(15, 15, 15)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(sangre_alum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(alergias, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblhora, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlbldia, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(52, 52, 52)
                .addComponent(jButton1)
                .addContainerGap(28, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
public void fecha(){
   String fecha=Fecha();
   jlbldia.setText(fecha);
}
    
public String nombre(int mes){
    switch(mes){
        case 0: return "Enero";
        case 1: return "Febrero";
        case 2: return "Marzo";
        case 3: return "Abril";
        case 4: return "Mayo";
        case 5: return "Junio";
        case 6: return "Julio";
        case 7: return "Agosto";
        case 8: return "Septiembre";
        case 9: return "Octubre";
        case 10: return "Noviembre";
        case 11: return "Diciembre";
    }
    
    return "Error";
}    
    
    public String Fecha(){
    GregorianCalendar fecha=new GregorianCalendar();
    int dia=fecha.get(fecha.DAY_OF_MONTH);
    int mes=fecha.get(fecha.MONTH);
    int año=fecha.get(fecha.YEAR);
    String mifecha=String.valueOf(dia)+"/"+nombre(mes)+"/"+String.valueOf(año);
    return mifecha;       
    }
    
 public void leerlineayllenarAlumnos() {
    String EXP = Busqueda_reporte1.Nexp_Alumno.getText();
            try { 
         // Busqueda_reporte1 br1 = new Busqueda_reporte1();
            BufferedReader br = new BufferedReader(new FileReader("src/ArchivosTXT/Alumnos.txt"));
            String expediente;
            while ((expediente = br.readLine()) != null) {
//en line se pone la línea y haces lo que necesites con ella
            if(expediente.startsWith(EXP)){    
                String[] alumno = expediente.split(";");
                nom_alumno.setText(alumno[1]+" "+alumno[2]+" "+alumno[3]);
                numex_alumno.setText(alumno[0]);
                sangre_alum.setText(alumno[6]);
                alergias.setText(alumno[7]);
              }  }          
        } catch (IOException x) {
            x.printStackTrace();
        }
    }  
 
 public void leerlineayllenarMaterias() {
    String EXP = Busqueda_reporte1.Clave_materia.getText();
            try { 
         // Busqueda_reporte1 br1 = new Busqueda_reporte1();
            BufferedReader br = new BufferedReader(new FileReader("src/ArchivosTXT/Materias.txt"));
            String Materias;
            while ((Materias = br.readLine()) != null) {
//en line se pone la línea y haces lo que necesites con ella
            if(Materias.startsWith(EXP)){    
                String[] materias = Materias.split(";");
                nom_materia.setText(materias[1]);
                clav_materia.setText(materias[0]);
              }  }          
        } catch (IOException x) {
            x.printStackTrace();
        }
    }  
 
 public void leerlineayllenarMaestros() {
    String EXP = Busqueda_reporte1.clave_maestro.getText();
            try { 
         // Busqueda_reporte1 br1 = new Busqueda_reporte1();
            BufferedReader br = new BufferedReader(new FileReader("src/ArchivosTXT/Maestros.txt"));
            String Maestros;
            while ((Maestros = br.readLine()) != null) {
//en line se pone la línea y haces lo que necesites con ella
            if(Maestros.startsWith(EXP)){    
                String[] maestros = Maestros.split(";");
                nom_maestro.setText(maestros[1]+" "+maestros[2]+" "+maestros[3]);
                clav_maestro.setText(maestros[0]);
              }  }          
        } catch (IOException x) {
            x.printStackTrace();
        }
    }   
 
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        validando();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void nom_materiaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nom_materiaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_nom_materiaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Reporte_1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Reporte_1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Reporte_1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Reporte_1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new Reporte_1().setVisible(true);
                } catch (IOException ex) {
                    Logger.getLogger(Reporte_1.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField alergias;
    private javax.swing.JTextField clav_maestro;
    private javax.swing.JTextField clav_materia;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jlbldia;
    private javax.swing.JLabel jlblhora;
    private javax.swing.JTextField nom_alumno;
    private javax.swing.JTextField nom_maestro;
    private javax.swing.JTextField nom_materia;
    public static javax.swing.JTextField numex_alumno;
    private javax.swing.JTextField sangre_alum;
    private javax.swing.JTextField semestre;
    // End of variables declaration//GEN-END:variables
 private void semestre() throws IOException {
        String EXP = Busqueda_reporte1.Nexp_Alumno.getText();
        String expediente;
        try {
//columna clave de la materia            
            BufferedReader clave = new BufferedReader(new FileReader("src/ArchivosTXT/Alta_Materia.txt"));
            while ((expediente = clave.readLine()) != null) {
                if (expediente.startsWith(EXP)) {
                    String[] clave_materia = expediente.split(";");
//columna nombre de la materia
                    BufferedReader nombre = new BufferedReader(new FileReader("src/ArchivosTXT/Materias.txt"));
                    while ((expediente = nombre.readLine()) != null) {
                        if (expediente.startsWith(clave_materia[1])) {
                            String[] datos_materias = expediente.split(";");

//columna creditos de la materia
                            BufferedReader credito = new BufferedReader(new FileReader("src/ArchivosTXT/Materias.txt"));
                            while ((expediente = credito.readLine()) != null) {
                                if (expediente.startsWith(clave_materia[1])) {

//columna semestre de cada materia del archivo materias                                    
                                    BufferedReader semestre2 = new BufferedReader(new FileReader("src/ArchivosTXT/Materias.txt"));
                                    while ((expediente = semestre2.readLine()) != null) {
                                        if (expediente.startsWith(clave_materia[1])) {
                                            String[] semestre_al = expediente.split(";");
                                            semestre.setText(semestre_al[3]);

                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(kardex.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
 
    public void validando() {
        String EXP = log.expedientes.getText();
        String pwd = log.claves_sesion2.getText();
        if (expedientes.getText().length() != 0 && claves_sesion2.getText().length() != 0) {
            try {

                BufferedReader alumnos = new BufferedReader(new FileReader("src/ArchivosTXT/Alumnos.txt"));
                String Materias;
                while ((Materias = alumnos.readLine()) != null) {

                    if (Materias.startsWith(EXP)) {
                        String[] Al = Materias.split(";");
                        if (Al[0].equals(EXP) && Al[22].equals(pwd)) {
                            
                            new inicio().setVisible(true);
                            this.setVisible(false);
                            inicio.constancia_inicio.setVisible(false);
                            inicio.reporte1.setVisible(false);
                            inicio.reporte2.setVisible(true);
                            inicio.reporte3.setVisible(false);
                            inicio.kardex_inicio.setVisible(true);
                            inicio.jMenu2.setVisible(false);
                        } else {
                            JOptionPane.showMessageDialog(null, "Datos Erroneos");
                        }
                    }
                }

                BufferedReader maestros = new BufferedReader(new FileReader("src/ArchivosTXT/Maestros.txt"));
                String Maestros;
                while ((Maestros = maestros.readLine()) != null) {
                    if (Maestros.startsWith(EXP)) {
                        String[] Ma = Maestros.split(";");
                        if (Ma[0].equals(EXP) && Ma[12].equals(pwd)) {
                            
                            new inicio().setVisible(true);
                            this.setVisible(false);
                            inicio.constancia_inicio.setVisible(false);
                            inicio.reporte1.setVisible(false);
                            inicio.reporte2.setVisible(true);
                            inicio.reporte3.setVisible(false);
                            inicio.kardex_inicio.setVisible(false);
                            inicio.jMenu2.setVisible(true);
                            inicio.alumno_inicio.setVisible(false);
                            inicio.maestro_inicio.setVisible(false);
                            inicio.materia_inicio.setVisible(false);
                            inicio.Calificaciones.setVisible(true);
                            inicio.jMenuItem6.setVisible(false);
                            //inicio.jMenuItem7.setVisible(false);

                        } else {
                            JOptionPane.showMessageDialog(null, "Datos Erroneos");
                        }
                    }
                }
                if (EXP.equals("Admin") && pwd.equals("Citrus")) {
                    
                    new inicio().setVisible(true);
                    this.setVisible(false);
                    constancia_inicio.setVisible(true);
                    inicio.reporte1.setVisible(true);
                    inicio.reporte2.setVisible(true);
                    inicio.reporte3.setVisible(true);
                    inicio.kardex_inicio.setVisible(true);
                    inicio.jMenu2.setVisible(true);
                    inicio.alumno_inicio.setVisible(true);
                    inicio.maestro_inicio.setVisible(true);
                    inicio.materia_inicio.setVisible(true);
                    inicio.Calificaciones.setVisible(true);
                    inicio.jMenuItem4.setVisible(true);
                    inicio.jMenuItem6.setVisible(true);
                    inicio.jMenuItem7.setVisible(true);
                } else {
                    JOptionPane.showMessageDialog(null, "Datos Erroneos");
                }
            } catch (IOException x) {
            }
        } else {
            JOptionPane.showMessageDialog(null, "Campos Requeridos");
        }
}

}
